
//
//  PickProjectTableView.swift
//  Wmsmobile
//
//  Created by Nick xu on 16/8/19.
//  Copyright © 2016年 www.hd123.com. All rights reserved.
//

import UIKit

class ChkBinInfoTableview: UITableView,UITableViewDelegate, UITableViewDataSource, DetailListCellDisplayViewProtcol {
    
    var realHeightDelegate: DetailListCellProtcol?
    
    var heightDelegate: DetailListCellProtcol?{
        set{
            realHeightDelegate = newValue
        }
        get{
            return realHeightDelegate
        }
    }
    var anyInfo:AnyObject?{
        didSet{
            //商品代码:20090829;;商品名称:货品5;; ;;规格:;;收货规格:1*1 长:10 宽:6 高:3 重:400;;收货规格:1*10 长:100 宽:60 高:30 重:4000;; ;;拣货信息：;;拣货规格:1*1 拣货位:11032811;; ;;供应商代码:000001;;供应商名称:供应商01;;供应商退货位:91081711
            let originString = anyInfo as? String
            var tempArray = [[String : String]]()
            guard strlen(originString ?? "") > 0 else {
                return
            }
            let string1 = originString?.components(separatedBy: ";; ;;")[1]
            var stringArray1 = string1?.components(separatedBy: ";;")
            stringArray1?.removeFirst()
            for item1 in stringArray1! { //收货规格:1*1 长:10 宽:6 高:3 重:400
                var dict = [String : String]()
                    let array = item1.components(separatedBy: " ")
                    let value1 = array[0].components(separatedBy: ":").last
                    dict.updateValue(value1!, forKey: "收货规格")
                    let value2 = "\(array[1].components(separatedBy: ":").last ?? "")/\(array[2].components(separatedBy: ":").last ?? "")/\(array[3].components(separatedBy: ":").last ?? "")"
                    dict.updateValue(value2, forKey: "长宽高")
                    let value3 = array[4].components(separatedBy: ":").last
                    dict.updateValue(value3!, forKey: "重量")
                    tempArray.append(dict)
            }
            dataArray = tempArray
        }
    }
    var dataArray:[[String : String]]?{
        didSet{
            self.reloadData()
            if self.delegate != nil{
                self.heightDelegate?.setRealHeight(44 * CGFloat((dataArray?.count)!))
            }
        }
    }
    //MARK: - life cycle
    override init(frame: CGRect, style: UITableViewStyle) {
        super.init(frame: frame, style: style)
        self.register(ChkBinInfoTableviewCell.self, forCellReuseIdentifier: "PickProjectTableViewCell")
        self.delegate = self
        self.dataSource = self
        self.isScrollEnabled = false
        self.dataArray = [["长宽高" : "无数据"]]
//        self.separatorStyle = .None
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    
    
    
    //MARK: - tableView dataSourece
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.dataArray?.count ?? 0
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var dict = self.dataArray![(indexPath as NSIndexPath).row]
        let cell = tableView.dequeueReusableCell(withIdentifier: "PickProjectTableViewCell") as! ChkBinInfoTableviewCell
        dict.updateValue(String((indexPath as NSIndexPath).row), forKey: "project")
        cell.info = dict
        return cell
    }
    
}
